home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROGS.ZIP
/
IPSORT.ICN
< prev
next >
Wrap
Text File
|
1992-09-28
|
2KB
|
69 lines
############################################################################
#
# File: ipsort.icn
#
# Subject: Program to sort Icon procedures
#
# Author: Ralph E. Griswold
#
# Date: June 10, 1988
#
###########################################################################
#
# This program reads an Icon program and writes an equivalent
# program with the procedures sorted alphabetically. Global, link,
# and record declarations come first in the order they appear in
# the original program. The main procedure comes next followed by
# the remaining procedures in alphabetical order.
#
# Comments and white space between declarations are attached to
# the next following declaration.
#
# Limitations: This program only recognizes declarations that start
# at the beginning of a line.
#
# Comments and interline white space between declarations may
# not come out as intended.
#
############################################################################
procedure main()
local line, x, i, proctable, proclist, comments, procname
comments := [] # list of comment lines
proctable := table() # table of procedure declarations
while line := read() do {
line ? {
if ="procedure" & # procedure declaration
tab(many('\t ')) &
procname := tab(upto('(')) | stop("*** bad syntax: ",line)
then { # if main, force sorting order
if procname == "main" then procname := "\0main"
proctable[procname] := x := []
while put(x,get(comments)) # save it
put(x,line)
while line := read() do {
put(x,line)
if line == "end" then break
}
}
# other declarations
else if =("global" | "record" | "link")
then {
while write(get(comments))
write(line)
}
else put(comments,line)
}
}
while write(get(comments))
proclist := sort(proctable,3) # sort procedures
while get(proclist) do
every write(!get(proclist))
end